package com.kiwilss.aopdemo.ui.dsl

import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.addTextChangedListener
import com.google.android.material.tabs.TabLayout
import com.kiwilss.aopdemo.R
import com.kiwilss.aopdemo.utils.LogUtils
import kotlinx.android.synthetic.main.activity_dsl.*
import kotlinx.android.synthetic.main.pw_center.*

/**
 * @author : Administrator
 * e-mail : kiwilss@163.com
 * time   : 2021/02/05
 *  desc   :
 */
class DslActivity : AppCompatActivity(R.layout.activity_dsl) {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

//        etDSLTest.addTextChangedListener(object :TextWatcher{
//            override fun afterTextChanged(s: Editable?) {
//
//            }
//
//            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
//            }
//
//            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
//            }
//
//        })
        //EditText 扩展函数使用

        etDSLTest.addTextChangedListener(
            textWatcher{
                onTextChanged { s, start, before, count ->
                    LogUtils.e(s)
                }
            })


        tlDSLTab.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
            override fun onTabReselected(tab: TabLayout.Tab?) {

            }

            override fun onTabUnselected(tab: TabLayout.Tab?) {
            }

            override fun onTabSelected(tab: TabLayout.Tab?) {
            }

        })
        //dsl 使用


        btnDSLPw.setOnClickListener {
            showDslPw()
        }
        btnDSLPw2.setOnClickListener { showDslPw2() }

    }

    private fun showDslPw2() {
        dslPw {
            mTitle = "DSL测试标题"
            mLeftDec = "取消"
            mRightDec = "确定"
            leftClick {
                dismiss()
            }
        }
    }

    private fun showDslPw() {
        val pw = DslPw(this)
        pw.mTitle = "DSL测试标题"
        pw.show()
    }
}